<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-物料库</title>
		<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/tag.css" />
		<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js"> </script>
		<link href="<%=request.getContextPath()%>/js/My97DatePicker/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript">
			function checkKey(){
			    var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;
			    var keyOfWord = $.trim(document.getElementById("keyOfWord").value);
			    document.getElementById("keyOfWord").value = keyOfWord;
			    if(keyOfWord != null && keyOfWord != '' &&!myReg.test(keyOfWord)){
                    alert('关键字搜索不能包括特殊字符！');
                    return false;			
			    }
			    doSubmit('materiallist.action');
			}
			
			function pageSub(currentPage) {
				var reg=/^\d*?$/;
				var total =${page.totalPages};
				if (reg.test(currentPage)) {
					if (currentPage > total) {
						$("#currentPage").val(total);
					} else {
						$("#currentPage").val(currentPage);
					}
				
					document.forms[0].action = "materiallist.action";
					document.forms[0].submit();
				} else {
					alert("请输入数字！");
				}
			}
		
			function doSubmit(url) {
				document.forms[0].action = url;
				document.forms[0].submit();
			}
			
			function deleteMaterial(matId) {
				if (confirm('确定删除该条记录？')) {
					$.ajax({
						url : 'delMaterialAction.action?matId=' + matId,
						type : "POST",
						cache : false,
						success : function(message) {
							if (message == "success") {
								alert("物料删除成功！");
								doSubmit('materiallist.action');
							} else if(message=="beUsed"){
								alert("物料已被使用，不能删除 ！ ");
								doSubmit('materiallist.action');
							}else if(message=="isDeleted"){
								alert("物料信息不存在！ ");
								doSubmit('materiallist.action');
							}else if(message=="error"){
								window.location.href="goError.action";

							}
						}
					});
				}
			}
			
			function rewlset()
		    {
				document.getElementById("firstStratTime").value="";
				document.getElementById("firstEndTime").value="";
				document.getElementById("type").value="";
				document.getElementById("city").value="${logUser.usercity}";
				document.getElementById("business").value="";
				//document.getElementById("materialOfSelect").value="0";
				document.getElementById("keyOfWord").value="请输入关键字";
			}
			
		    	    //下载文件
			 function downloadFile(fileName)
		   {
			   if(fileName!=null&&fileName!="")
			   {
				   var url = encodeURI(encodeURI("downLoadMaterialFileName.action?fileName=" +fileName));
				   window.location.href=url;
			   }
		   }
	  
    </script>
	</head>

	<body>
		<!-- 顶栏start -->
		<jsp:include page="../common/top.jsp"></jsp:include>
		<!-- 顶栏end -->
		
		<!-- 顶部start -->
		<div id="main">
			<div class="body">
				<!-- 导航菜单 -->
				<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<div class="main_body">
					<form action="" method="post">
					  <input type="hidden" name="types" value="${types}"/>
					  <input type="hidden" name="types" value="${code}"/>
						<table class="condition bg1"
							style="width: 100%; font-size: 14px; font-weight: bold; color: #000000;"
							align="center">
							<tr>
								
								<td width="9%" style="height: 40px; text-align:right;">
							
									<label>最初上线时间：</label>
								</td>
								<td width="30%" style="height: 40px;">
									<input type="text" class="text Wdate" name="firstStratTime" id="firstStratTime" readonly="readonly"
									value="${firstStratTime}" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'firstEndTime\')||\'2050-10-01\'}'});" />
									-
									<input type="text" class="text Wdate" name="firstEndTime" id="firstEndTime" readonly="readonly"
									value="${firstEndTime}" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'firstStratTime\')}',maxDate:'2050-10-01'})"  />
								</td>
								<td width="46%" colspan="3"  style="height:40px; text-align:left;">
									<s:select  name="type" id="type" list="dataListWLLX"
										listKey="id" listValue="datavalue" headerKey="" headerValue="--物料类型--"
										>
								    </s:select>
								    &nbsp;&nbsp;
									<s:select name="city" id="city" list="dataListCITY"
										listKey="id" listValue="datavalue" >
									</s:select>
									&nbsp;&nbsp;
									<s:select name="business" id="business" list="dataListWLYWLX"
										listKey="id" listValue="datavalue" headerKey="" headerValue="--业务类型--">
									</s:select>
									
								</td>
							</tr>
							<tr>
								<td style="height:40px; text-align:right;">
									<label>
										关键字：
									</label>
								</td>
								<td style="height:40px;">
									<s:select name="materialOfSelect" id="materialOfSelect"  list="#{1:'按物料编号'}"
										listKey="key" listValue="value"  >
									</s:select>
									&nbsp;
									<s:if test="%{null != keyOfWord && keyOfWord !=''}">
									<input name="keyOfWord" id="keyOfWord" type="text" class="text" value="${keyOfWord}" style= "text-valign:middle; line-height:22px; " 
									onfocus="if(this.value == '请输入关键字')this.value=''"  onblur="if(this.value=='')this.value='请输入关键字'"/>
									</s:if>
									<s:else>
									<input name="keyOfWord" id="keyOfWord" type="text" class="text" value="请输入关键字" style= "text-valign:middle; line-height:22px; " 
									onfocus="if(this.value == '请输入关键字')this.value=''"  onblur="if(this.value=='')this.value='请输入关键字'"/>
									</s:else>
								</td>
								
								<td style="height: 40px;" colspan="3">
									<input name="button" type="button" class="btn-title" value="搜索"
										onclick="checkKey();" />
									&nbsp;
									<input name="button" type="button" class="btn-title" value="重置" onclick="rewlset();" />
								</td>

								<td style="height: 40px; text-align: right; padding-right:20px;" >
									<input type="button" value="物料导入" class="btn-title" onclick="doSubmit('toUploadMaterialAction.action');"/>
									&nbsp;&nbsp;
									<input name="button" type="button" class="btn-title" value="新增"
										onclick="doSubmit('toAddMaterialAction.action');" />
									
								</td>
							</tr>
						</table>
						<div id="list_div">
							<input type="hidden" name="currentPage" id="currentPage" />
							<input type="hidden" name="ID" id="ID" value="mp.matId" />
							<table class="table_list" style="width: 100%;" align="center">
								<tr class="bg">
									<th>物料编号</th>
									<th>物料名称</th>
									<th>归属城市</th>
									<th>业务类型</th>
									<th>物料类型</th>
									<th>物料级别</th>
									<th>最初上线时间</th>
									<th>物料排序</th>
									<th>物料文件</th>
									<th>操作</th>
								</tr>
								<s:iterator value="list" id="mp">
									<tr>
										<td title="${mp.materialID}">${fn:substring(mp.materialID, 0, 20) }</td>
										<td title="${mp.materialName}">${fn:substring(mp.materialName, 0, 15) }</td>
										
										<td>
										<s:iterator value="dataListCITY" id="cl">
							            <s:if test="#cl.id == #mp.ownCity">
								            ${cl.datavalue}
							            </s:if>
						                </s:iterator>
						                </td>
										<td>
										<s:iterator value="dataListWLYWLX" id="c2">
							            <s:if test="#c2.id == #mp.serviceType">
								            ${c2.datavalue}
							            </s:if>
						                </s:iterator>
						                </td>
										
										<td>
										<s:iterator value="dataListWLLX" id="c3">
							            <s:if test="#c3.id == #mp.materialType">
								            ${c3.datavalue}
							            </s:if>
						                </s:iterator>
										</td>
										
										<td>
										<s:iterator value="dataListWLJB" id="c4">
							            <s:if test="#c4.id == #mp.materialLevel">
								            ${c4.datavalue}
							            </s:if>
						                </s:iterator>
										</td>
										
										<td>${fn:substring(mp.firstUpTime, 0, 10)}</td>
										<td>${mp.orderCol}</td>
										<td>
										<s:if test="%{null != materialContent && materialContent !=''}">
										<a href="javascript:downloadFile('${mp.materialContent}');" title="下载">
											<img src="<%=request.getContextPath()%>/images/download.gif" /></a>
										</s:if>
										<s:else>
										&nbsp;暂无
										</s:else>
										</td>
										<td>
										<s:if test="#session.logUser.usercity == ownCity">
											<a href="toEditMaterialAction.action? matId=${mp.matId} " title="编辑" type="POST"> 
											<img src="<%=request.getContextPath()%>/images/modify.gif"
													alt="编辑" align="middle" /> </a>
										</s:if>
													
											<a href="materialDetailAction.action? matId=${mp.matId} " title="详情"> 
											<img src="<%=request.getContextPath()%>/images/detail.gif"
											alt="详情" align="middle" /> </a>
											
										<s:if test="#session.logUser.usercity == ownCity">
											<a href="#" onclick="javascript:deleteMaterial('${mp.matId}');" title="删除"> 
												<img src="<%=request.getContextPath()%>/images/delete.gif"
													alt="删除" align="middle" /> </a>
										</s:if>
										</td>
									</tr>
								</s:iterator>
							</table>
							<!-- 分页 -->
							<jsp:include page="/jsp/common/page.jsp"></jsp:include>
						</div>

					</form>
				</div>
			</div>
		</div>
		
		<!-- 顶部end -->


		<!-- 底部start -->
		<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
		<!-- 底部end -->
	</body>
</html>
